/*
 * Copyright 2011 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package it.davial.mgwt.client.activities.patient.detail;

import it.davial.mgwt.client.Patient;
import it.davial.mgwt.client.activities.BaseViewImpl;
import it.davial.mgwt.client.resources.ResourceAware;
import it.davial.mgwt.client.ui.widget.base.HasPatientForm;

import java.util.logging.Logger;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasText;
import com.googlecode.mgwt.dom.client.event.tap.HasTapHandlers;
import com.googlecode.mgwt.ui.client.MGWT;
import com.googlecode.mgwt.ui.client.widget.HeaderButton;
import com.googlecode.mgwt.ui.client.widget.WidgetList;

/**
 * Sample implementation of {@link PatientDetailView}.
 */
public class PatientDetailViewImpl extends BaseViewImpl implements PatientDetailView,ResourceAware {

	private static final Logger logger = Logger.getLogger("PatientViewImpl");
	private WidgetList list;
	private Button button;	
	private HeaderButton bBack;
	private HeaderButton bSave;
	private Patient patient;
	private PatientDetailFormViewImpl form = new PatientDetailFormViewImpl();
	
	public PatientDetailViewImpl() {
		bBack = new HeaderButton();
		bBack.setBackButton(true);
		bBack.setText("Back");
		bSave = new HeaderButton();
/*		ButtonBar bb = new ButtonBar();
		bb.setStyleName(mainBundle.getMainCss().buttonBar());
		bb.add(bBack);
*/		headerPanel.setRightWidget(bSave);
		headerPanel.setLeftWidget(bBack);

		if (MGWT.getOsDetection().isPhone()) {
			button = new Button("back");
			button.getElement().setAttribute("style", "margin:auto;width: 200px;display:block");
			list.add(button);
			headerBackButton.removeFromParent();
		}

		scrollPanel.setWidget(form);
		scrollPanel.setScrollingEnabledX(false);
	}

	@Override
	public HasTapHandlers getBack() {
		return bBack;
	}

	@Override
	public HasTapHandlers getSave() {
		return bSave;
	}

	@Override
	public HasText getSaveButtonText() {
		return bSave;
	}

	@Override
	public HasPatientForm getPatientForm() {
		return form;
	}

	@Override
	public Patient getPatient() {
		patient = form.createPatient();
		return patient;
	}

	@Override
	public void setPatient(Patient patient) {
		this.patient = patient;
		form.fillForm(patient);
		
	}


	
}
